//! Modern UI components inspired by Shadcn UI

pub mod button;
pub mod card;
pub mod input;
pub mod tabs;
pub mod badge;
pub mod separator;
pub mod sql_editor;
pub mod database_explorer;
pub mod query_history;
pub mod ai_assistant;
pub mod table;

pub use button::*;
pub use card::*;
pub use input::*;
pub use tabs::*;
pub use badge::*;
pub use separator::*;
pub use table::*;

use iced::{Element, Length, Padding};
use iced::widget::{container, Container};
use crate::theme::CdbTheme;

/// Spacing constants following Shadcn UI design system
pub mod spacing {
    pub const XS: u16 = 4;   // 0.25rem
    pub const SM: u16 = 8;   // 0.5rem
    pub const MD: u16 = 12;  // 0.75rem
    pub const LG: u16 = 16;  // 1rem
    pub const XL: u16 = 20;  // 1.25rem
    pub const XXL: u16 = 24; // 1.5rem
    pub const XXXL: u16 = 32; // 2rem
}

/// Border radius constants
pub mod radius {
    pub const SM: f32 = 4.0;   // 0.25rem
    pub const MD: f32 = 6.0;   // 0.375rem
    pub const LG: f32 = 8.0;   // 0.5rem
    pub const XL: f32 = 12.0;  // 0.75rem
}

/// Shadow constants
pub mod shadow {
    use iced::Color;

    pub const SM: Color = Color::from_rgba(0.0, 0.0, 0.0, 0.05);
    pub const MD: Color = Color::from_rgba(0.0, 0.0, 0.0, 0.1);
    pub const LG: Color = Color::from_rgba(0.0, 0.0, 0.0, 0.15);
    pub const XL: Color = Color::from_rgba(0.0, 0.0, 0.0, 0.25);
}

/// Typography scale
pub mod typography {
    pub const XS: u16 = 12;   // 0.75rem
    pub const SM: u16 = 14;   // 0.875rem
    pub const BASE: u16 = 16; // 1rem
    pub const LG: u16 = 18;   // 1.125rem
    pub const XL: u16 = 20;   // 1.25rem
    pub const XXL: u16 = 24;  // 1.5rem
    pub const XXXL: u16 = 30; // 1.875rem
    pub const XXXXL: u16 = 36; // 2.25rem
}

/// Create a modern container with Shadcn UI styling
pub fn modern_container<'a, Message>(
    content: Element<'a, Message>,
    theme: &'a CdbTheme,
) -> Container<'a, Message> {
    container(content)
        .style(move |_theme| {
            container::Style {
                background: Some(theme.colors.card.into()),
                border: iced::Border {
                    color: theme.colors.border,
                    width: 1.0,
                    radius: radius::LG.into(),
                },
                shadow: iced::Shadow {
                    color: shadow::SM,
                    offset: iced::Vector::new(0.0, 1.0),
                    blur_radius: 3.0,
                },
                ..Default::default()
            }
        })
        .padding(spacing::LG)
}

/// Create a glass-morphism effect container
pub fn glass_container<'a, Message>(
    content: Element<'a, Message>,
    theme: &'a CdbTheme,
) -> Container<'a, Message> {
    container(content)
        .style(move |_theme| {
            container::Style {
                background: Some(
                    iced::Color {
                        a: 0.8,
                        ..theme.colors.card
                    }.into()
                ),
                border: iced::Border {
                    color: iced::Color {
                        a: 0.2,
                        ..theme.colors.border
                    },
                    width: 1.0,
                    radius: radius::LG.into(),
                },
                shadow: iced::Shadow {
                    color: shadow::LG,
                    offset: iced::Vector::new(0.0, 4.0),
                    blur_radius: 6.0,
                },
                ..Default::default()
            }
        })
        .padding(spacing::LG)
}

/// Create a sidebar container
pub fn sidebar_container<'a, Message>(
    content: Element<'a, Message>,
    theme: &'a CdbTheme,
) -> Container<'a, Message> {
    container(content)
        .style(move |_theme| {
            container::Style {
                background: Some(theme.colors.muted.into()),
                border: iced::Border {
                    color: theme.colors.border,
                    width: 1.0,
                    radius: 0.0.into(),
                },
                ..Default::default()
            }
        })
        .padding(spacing::LG)
        .width(Length::Fixed(280.0))
        .height(Length::Fill)
}

/// Create a main content area container
pub fn content_container<'a, Message>(
    content: Element<'a, Message>,
    theme: &'a CdbTheme,
) -> Container<'a, Message> {
    container(content)
        .style(move |_theme| {
            container::Style {
                background: Some(theme.colors.background.into()),
                ..Default::default()
            }
        })
        .padding(spacing::LG)
        .width(Length::Fill)
        .height(Length::Fill)
}

/// Create a header container
pub fn header_container<'a, Message>(
    content: Element<'a, Message>,
    theme: &'a CdbTheme,
) -> Container<'a, Message> {
    container(content)
        .style(move |_theme| {
            container::Style {
                background: Some(theme.colors.card.into()),
                border: iced::Border {
                    color: theme.colors.border,
                    width: 1.0,
                    radius: 0.0.into(),
                },
                ..Default::default()
            }
        })
        .padding(Padding::from([spacing::MD, spacing::LG]))
        .width(Length::Fill)
}

/// Create a status bar container
pub fn status_bar_container<'a, Message>(
    content: Element<'a, Message>,
    theme: &'a CdbTheme,
) -> Container<'a, Message> {
    container(content)
        .style(move |_theme| {
            container::Style {
                background: Some(theme.colors.muted.into()),
                border: iced::Border {
                    color: theme.colors.border,
                    width: 1.0,
                    radius: 0.0.into(),
                },
                ..Default::default()
            }
        })
        .padding(Padding::from([spacing::SM, spacing::LG]))
        .width(Length::Fill)
}
